{% assign maxRelated = 5 %}

{% assign minCommonTags =  2 %}

{% assign maxRelatedCounter = 0 %}

{% for post in site.posts %}

    {% assign sameTagCount = 0 %}
    {% assign commonTags = '' %}

    {% for tag in post.tags %}
        {% if post.url != page.url %}
            {% if page.tags contains tag %}
            {% assign sameTagCount = sameTagCount | plus: 1 %}
            {% capture tagmarkup %}
                <span class="tag is-small is-link is-light">{{ tag }}</span>
            {% endcapture %}
            {% assign commonTags = commonTags | append: tagmarkup %}
            {% endif %}
        {% endif %}
    {% endfor %}

    {% if sameTagCount >= minCommonTags %}
        {% if maxRelatedCounter == 0 %}
            <aside class="menu">
                <p class="menu-label">相关文章</p>
                <ul class="menu-list">
        {% endif %}
        <li><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}{{ commonTags }}</a></li>
        {% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
        {% if maxRelatedCounter >= maxRelated %}
            {% break %}
        {% endif %}
    {% endif %}

{% endfor %}

{% if maxRelatedCounter != 0 %}
    </ul>
    </aside>
{% endif %}